package net.lahuobao.mall.controller.admin;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.lahuobao.mall.entity.admin.MallArticleEntity;
import net.lahuobao.mall.entity.admin.MallShopAuditEntity;
import org.apache.log4j.Logger;
import org.jeecgframework.core.util.ContextHolderUtils;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.pojo.base.TSDepart;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.core.util.MyBeanUtils;

import net.lahuobao.mall.entity.admin.MallShopEntity;
import net.lahuobao.mall.service.admin.MallShopServiceI;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.jeecgframework.core.beanvalidator.BeanValidators;
import java.util.Set;
import javax.servlet.http.HttpSession;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.net.URI;
import org.springframework.http.MediaType;
import org.springframework.web.util.UriComponentsBuilder;

/**   
 * @Title: Controller
 * @Description: 店铺审核
 * @author zhangdaihao
 * @date 2016-10-14 09:39:08
 * @version V1.0   
 *
 */
@Controller
@RequestMapping("/mallShopController")
public class MallShopController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(MallShopController.class);

	@Autowired
	private MallShopServiceI mallShopService;
	@Autowired
	private SystemService systemService;
	@Autowired
	private Validator validator;
	


	/**
	 * 店铺审核列表 页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "list")
	public ModelAndView list(HttpServletRequest request) {
		return new ModelAndView("net/lahuobao/mall/admin/mallShopList");
	}
	/**
	 * 店铺审核列表 页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "chooseList")
	public ModelAndView chooseList(HttpServletRequest request) {
		return new ModelAndView("net/lahuobao/mall/admin/shopChooseList");
	}
	/**
	 * easyui AJAX请求数据
	 * 
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param
	 */

	@RequestMapping(params = "datagrid")
	public void datagrid(MallShopEntity mallShop,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(MallShopEntity.class, dataGrid);

		//查询条件组装器
		if(StringUtil.isNotEmpty(mallShop.getShopname())){
			cq.like("shopname", "%"+mallShop.getShopname()+"%");
			mallShop.setShopname(null);
		}

		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, mallShop, request.getParameterMap());
		this.mallShopService.getDataGridReturn(cq, true);
		TagUtil.datagrid(response, dataGrid);
	}

	/**
	 * easyui AJAX请求数据
	 *
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param
	 */

	@RequestMapping(params = "chooseDatagrid")
	public void chooseDatagrid(MallShopEntity mallShop,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(MallShopEntity.class, dataGrid);

		//查询条件组装器
		if(StringUtil.isNotEmpty(mallShop.getShopname())){
			cq.like("shopname", "%"+mallShop.getShopname()+"%");
			mallShop.setShopname(null);
		}

		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, mallShop, request.getParameterMap());
		this.mallShopService.getDataGridReturn(cq, true);
		TagUtil.datagrid(response, dataGrid);
	}

	@RequestMapping(params = "upstatus")
	@ResponseBody
	public AjaxJson upstatus(MallShopAuditEntity  mallShopAudit, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		try {
			//操作人
			mallShopAudit.setUserid(1);
			mallShopService.upStatus(mallShopAudit);
		} catch (Exception e) {
			e.printStackTrace();
			j.setSuccess(false);
			j.setMsg("操作失败！");
		}
		return j;
	}

}
